﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

/**
 * 创建时间：2014/12/5 10:18:12
 * 作者：yong.blackcore
 * Email：itblackhole@outlook.com
 * QQ：50404503
 */
namespace ComicIsland.Common.Converter
{
    public class FontSizeConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            try
            {
                double fontsize = 18;
                int strLength = 10;
                if (!int.TryParse(parameter.ToString(), out strLength))
                {
                    strLength = 10;
                }
                if (value == null)
                    return fontsize;

                string s = value.ToString();
                if (Encoding.Unicode.GetBytes(s).Length > 10)
                    fontsize = 15;

                return fontsize;
            }
            catch (Exception err)
            {
                LogHelper.LogError(err.Message, this.GetType(), MethodBase.GetCurrentMethod());
                return "";
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
    }
}
